/* chunking.h
 the main fuction is to chunking the file!
 */

#ifndef RABIN_H_
#define RABIN_H_

#include<assert.h>
#include <immintrin.h>
#define CHUNK_RABIN 1
#define CHUNK_NORMALIZED_RABIN 2

struct superF
{
	uint64_t sf1;
	uint64_t sf2;
	uint64_t sf3;
	uint64_t sf4;
};

struct {
	int chunk_max_size;
	int chunk_min_size;
	int chunk_avg_size;
    int super_feature_subregion_num;
    int features_per_sf;
    int enable_sort_features;
    int chunk_algorithm;
} destor;

struct RabinWindowAvx8 {
	unsigned char *p;

	unsigned int i;
	unsigned int j;
	unsigned int subregion_size;

	__m512i vindex;
	__m512i cmask;
	__m512i hash;

	__m512i dmask;
	__m512i break_mark;
	__m512i cbytes;
	__m512i kickBytes;
};

#define MSB64 0x8000000000000000LL
#define MAXBUF (128*1024) 

#define FINGERPRINT_PT  0xbfe6b8a5bf378d83LL
#define BREAKMARK_VALUE 0x78

#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))

int rabin_chunk_data(unsigned char *p, int n);
void chunkAlg_init();
void gear_init();
void windows_reset();
void super_feature(unsigned char* p, int n, struct superF* SF);
void sisd_rabin_fixed(unsigned char* p, int n, struct superF* SF);
void sisd_gear_fixed(unsigned char* p, int n, struct superF* SF);
void fastcdc_init(uint32_t expectCS);
uint64_t fastcdc_chunk_data(unsigned char *p, int n);

#endif

